/**
 * @author Evgeny Sorokin
 */
Ext.Loader.setConfig({
	enabled : true,
	disableCaching : true
});
Ext.application({
    name: 'USocial',

    requires: [
        'Ext.MessageBox',
        'USocial.Util',
        'USocial.util.Geolocation'
    ],

    stores : [
    	'USocial.store.FriendsStore',
    	'USocial.store.AppUserStore',
    	'USocial.store.FriendsAppUsersStore'
    ],
    models : [
        'USocial.model.User',
    	'USocial.model.UserInfo'
    ],
    views: [
        'USocial.view.Login',
        'USocial.view.Main',
        'USocial.view.Map',
        'USocial.view.InviteFriendsList',
        'USocial.view.InviteFriendsPanel',
        'USocial.view.MainBar',
        'USocial.view.PostMessageModal',
        'USocial.view.MapPanel',
        'BrowseFile'
    ],
    controllers : [
    	'MarkersPlace',
    	'LocationUpdate',
    	'ApproachCheck',
    	'PostMessage'
    ],
    
    icon: {
        '57': 'resources/icons/Icon.png',
        '72': 'resources/icons/Icon~ipad.png',
        '114': 'resources/icons/Icon@2x.png',
        '144': 'resources/icons/Icon~ipad@2x.png'
    },

    isIconPrecomposed: true,

    startupImage: {
        '320x460': 'resources/startup/320x460.jpg',
        '640x920': 'resources/startup/640x920.png',
        '768x1004': 'resources/startup/768x1004.png',
        '748x1024': 'resources/startup/748x1024.png',
        '1536x2008': 'resources/startup/1536x2008.png',
        '1496x2048': 'resources/startup/1496x2048.png'
    },
    
    setUserInfo : function(userInfo){
    	this.userInfo = userInfo;
    },
    
    getUserInfo : function(){
    	return this.userInfo;
    },
    
 	_configureStoreProxies : function(){
		this.getStores().forEach(function(store){
			
			if(store.buildProxy){
				store.buildProxy();
				store.load();
			}
		})		
 	},

    launch: function() {
    	var me = this;
    	
        Ext.fly('appLoadingIndicator').destroy();
        
        USocial.Util.getUserInfo(function(userInfo){
			
        	if(userInfo.get('token')){
        		
        		me.setUserInfo(userInfo);
				
        		me._configureStoreProxies();
				
        		Ext.Viewport.add(Ext.create('USocial.view.Main'));
        		
	        }else{
		        Ext.Viewport.add(Ext.create('USocial.view.Login'));
	        }
      	 });
    }
});
